var api = require('../../config/api.js');
var utils = require('../../utils/util.js')
var app = getApp();

Page({
  data: {
    mobile: '',
    password: '',
    code: '',
    loginErrorCount: 0
  },
  onLoad: function (options) {
    this.setData({
      mobile: app.globalData.mobile,
      password: app.globalData.password,
    });
  },
  startLogin: function () {
    var that = this;
    if (that.data.password.length < 1 || that.data.mobile.length < 1) {
      business.showModal({
        title: '登录',
        content: '请输入手机号和密码',
        showCancel: false
      });
      return false;
    }
    business.request({
      url: api.BindWechat,
      data: {
        mobile: that.data.mobile,
        password: that.data.password,
        openId: business.getStorageSync('openId')
      },
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        business.switchTab({ url: '/pages/index/index' });
      }
    });
  },
  bindUsernameInput: function (e) {
    this.setData({ mobile: e.detail.value });
  },
  bindPasswordInput: function (e) {
    this.setData({ password: e.detail.value });
  },
  bindCodeInput: function (e) {
    this.setData({ code: e.detail.value });
  },
  goGuest: function (e) {
    business.navigateTo({ url: '../guest/guest' })
  },
  qrCode: function (e) {
    business.navigateTo({ url: '../qrcode/index' })
  }
})